import axios from 'axios'

const instance = axios.create({
  baseURL: 'http://localhost:9090/',
  // timeout: 1000,
  // headers: {'X-Custom-Header': 'foobar'}
});

// 请求拦截器
instance.interceptors.request.use(function (config) {
  // Do something before request is sent
  return config;
}, function (error) {
  // Do something with request error
  return Promise.reject(error);
});

// 响应拦截器
instance.interceptors.response.use(function (response) {
  
  if(response.data.code != 0){
    ElMessage.error(response.data.msg);
    return;
  }

  return response.data;
}, function (error) {
  // Any status codes that falls outside the range of 2xx cause this function to trigger
  // Do something with response error
  return Promise.reject(error);
});

export default instance;